﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace KhoaLuan.ProcessAJAX
{
    /// <summary>
    /// Summary description for UploadFileAJAX
    /// </summary>
    public class UploadFileAJAX : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var httpPostedFile = context.Request.Files["File"];
                if (httpPostedFile != null)
                {
                    string filename = "~/Images/Uploads/" + DateTime.Now.ToString("ddMMyyyyhhmmss") + httpPostedFile.FileName;
                    httpPostedFile.SaveAs(HttpContext.Current.Server.MapPath(filename));
                    //da import thanh cong, xu ly import o day
                    context.Response.Write(new JavaScriptSerializer().Serialize(new { Status = true, Location = filename }));
                }
                else
                {
                    context.Response.Write(new JavaScriptSerializer().Serialize(new { Status = false }));
                }
            }
            catch (Exception)
            {
                context.Response.Write(new JavaScriptSerializer().Serialize(new { Status = false }));

            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}